package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.entity.Account;
import com.example.springboot.service.AdminService;
import com.example.springboot.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class WebController {

    @Resource
    AdminService adminService;
    @Resource
    UserService userService;

    @PostMapping("/login")
    public Result login(@RequestBody Account account){
        Account dbAccount = null;
        if ("ADMIN".equals(account.getRole())){
            dbAccount = adminService.login(account);
        }else if ("USER".equals(account.getRole())){
            dbAccount = userService.login(account);
        }
        return Result.success(dbAccount);
    }
}
